{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# 修整"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import time\n",
    "import os\n",
    "try:\n",
    "    file=open(\"index.json\",\"r\",encoding='utf-8')\n",
    "    indexfilejs=json.load(file)\n",
    "    file.close()\n",
    "except IOError:\n",
    "    indexfilejs={}\n",
    "\n",
    "hash=input(\"hash:\")\n",
    "\n",
    "file=open(indexfilejs[\"data\"][hash][\"origin\"][13:],\"r\",encoding='utf-8')\n",
    "detailfilejs=json.load(file)\n",
    "file.close()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "0 - hash - 9Aworks-1\n1 - headline - 善良是朵美丽的花\n2 - body - /articlelist/9Aworks-1.zpackage_article\n3 - datePublished - 2021-01-17\n4 - datePublishedtime - \n5 - dateModified - 2021-01-17\n6 - dateModifiedtime - \n7 - handwrittenexist - False\n8 - originwordexist - /articlelist/善良是朵美丽的花.docx\n9 - fictionmaterial - True\n10 - beingVotedDown - False\n11 - handwrittenURL - Not Exist\n12 - originwordURL - Not Exist\n13 - beingStarred - Not Exist\n14 - scoreExist - Not Exist\n15 - getScore - Not Exist\n"
     ]
    }
   ],
   "source": [
    "typelist={\n",
    "\"hash\":\"string\",\n",
    "\"headline\":\"string\",\n",
    "\"body\":\"string\",\n",
    "\"datePublished\":\"string\",\n",
    "\"datePublishedtime\":\"string\",\n",
    "\"dateModified\":\"string\",\n",
    "\"dateModifiedtime\":\"string\",\n",
    "\"handwrittenexist\":\"bool\",\n",
    "\"originwordexist\":\"bool\",\n",
    "\"fictionmaterial\":\"bool\",\n",
    "\"beingVotedDown\":\"bool\",\n",
    "\"handwrittenURL\":\"string\",\n",
    "\"originwordURL\":\"string\",\n",
    "\"beingStarred\":\"bool\",\n",
    "\"scoreExist\":\"bool\",\n",
    "\"getScore\":\"int\"\n",
    "}\n",
    "linker=[]\n",
    "i=0\n",
    "for o in typelist:\n",
    "    linker.append(o)\n",
    "    if(detailfilejs[\"data\"].get(o)!=None):\n",
    "        print(str(i) + \" - \"+o+\" - \"+str(detailfilejs[\"data\"][o]))\n",
    "    else:\n",
    "        print(str(i) + \" - \"+o+\" - Not Exist\")\n",
    "    i=i+1\n",
    "\n",
    "while True:\n",
    "    i=int(input(\"选择一项，-1 refer to ‘end’\"))\n",
    "    if(i==-1):\n",
    "        break\n",
    "    if(typelist[linker[i]]==\"bool\"):\n",
    "        tmp=int(input(\"set to (1-True/0-False):\"))\n",
    "        detailfilejs[\"data\"][linker[i]]=tmp==1\n",
    "    if(typelist[linker[i]]==\"string\"):\n",
    "        detailfilejs[\"data\"][linker[i]]=input(\"set to (string):\")\n",
    "    if(typelist[linker[i]]==\"int\"):\n",
    "        detailfilejs[\"data\"][linker[i]]=int(input(\"set to (int):\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "请确认\n\n0 - hash - 9Aworks-1\n1 - headline - 善良是朵美丽的花\n2 - body - /articlelist/9Aworks-1.zpackage_article\n3 - datePublished - 2021-01-17\n4 - datePublishedtime - \n5 - dateModified - 2021-01-17\n6 - dateModifiedtime - \n7 - handwrittenexist - False\n8 - originwordexist - /articlelist/善良是朵美丽的花.docx\n9 - fictionmaterial - True\n10 - beingVotedDown - False\n11 - handwrittenURL - Not Exist\n12 - originwordURL - Not Exist\n13 - beingStarred - False\n14 - scoreExist - True\n15 - getScore - 52\n"
     ]
    }
   ],
   "source": [
    "print(\"请确认\\n\")\n",
    "i=0\n",
    "for o in typelist:\n",
    "    if(detailfilejs[\"data\"].get(o)!=None):\n",
    "        print(str(i) + \" - \"+o+\" - \"+str(detailfilejs[\"data\"][o]))\n",
    "    else:\n",
    "        print(str(i) + \" - \"+o+\" - Not Exist\")\n",
    "    i=i+1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "indexfilejs[\"data\"][hash][\"timestamp\"]=int(time.time())\n",
    "\n",
    "file_index=open(\"index.json\",\"w\",encoding='utf-8')\n",
    "file_detail=open(indexfilejs[\"data\"][hash][\"origin\"][13:],\"w\",encoding='utf-8')\n",
    "\n",
    "file_index_out=json.dumps(indexfilejs,sort_keys=True,indent=4,ensure_ascii=False)\n",
    "file_detail_out=json.dumps(detailfilejs,sort_keys=True,indent=4,ensure_ascii=False)\n",
    "\n",
    "file_index.write(file_index_out)\n",
    "file_detail.write(file_detail_out)\n",
    "\n",
    "file_index.close()\n",
    "file_detail.close()"
   ]
  }
 ]
}